<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card>
      <!-- 搜索部分 -->
      <el-row :gutter="20">
        <el-col :span="8">
          <el-input placeholder="请输入内容" clearable>
            <el-button slot="append" icon="el-icon-search"></el-button>
          </el-input>
        </el-col>
      </el-row>

      <!-- 表格部分 -->
      <el-table :data="ordersList" stripe style="width: 100%" border>
        <el-table-column type="index" label="#"> </el-table-column>
        <el-table-column
          prop="order_number"
          label="订单编号"
          width="450px"
        >
        </el-table-column>
        <el-table-column prop="order_price" label="订单价格">
        </el-table-column>
        <el-table-column label="是否付款">
          <template slot-scope="scope">
            <el-tag type="success" v-if="scope.row.pay_status === '1'"
              >已付款</el-tag
            >
            <el-tag type="danger" v-else>未付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="is_send" label="是否发货">
        </el-table-column>
        <el-table-column prop="add_time" label="下单时间" width="140px">
          <template slot-scope="scope">
            {{ scope.row.create_time | dateFormat }}
          </template>
        </el-table-column>
        <el-table-column label="操作" width="125px">
          <template>
            <el-button
              type="primary"
              icon="el-icon-edit"
              size="mini"
              @click="ShowEditAddress"
            ></el-button>
            <el-button
              size="mini"
              type="success"
              icon="el-icon-location"
              @click="showProgress"
            ></el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="this.queryInfo.pagenum"
        :page-sizes="[3, 5, 10, 15]"
        :page-size="this.queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="this.total"
      >
      </el-pagination>
    </el-card>

    <!-- 编辑地址弹出框 -->
    <el-dialog
      title="提示"
      :visible.sync="editAddressDialogVisibale"
      width="50%"
      @close="resetEditAddressForm"
    >
      <el-form
        :model="editAddressForm"
        :rules="editAddressFormRules"
        ref="editAddressFormRef"
        label-width="100px"
      >
        <el-form-item label="省市区/县：" prop="address1">
          <el-cascader
            v-model="editAddressForm.address1"
            :options="citydata"
            :props="{ expandTrigger: 'hover' }"
          ></el-cascader>
        </el-form-item>
        <el-form-item label="详细地址：" prop="address2">
          <el-input v-model="editAddressForm.address2"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="editAddressDialogVisibale = false"
          >取 消</el-button
        >
        <el-button
          type="primary"
          @click="editAddressDialogVisibale = false"
          >确 定</el-button
        >
      </span>
    </el-dialog>

    <!-- 物流进度弹出框 -->
    <el-dialog
      title="物流进度"
      :visible.sync="progressVisible"
      width="50%"
    >
    </el-dialog>
  </div>
</template>

<script>
import citydata from './citydata'
export default {
  name: 'Order',
  components: {},
  props: {},
  data() {
    return {
      ordersList: [],
      queryInfo: {
        query: '',
        pagenum: 1,
        pagesize: 10
      },
      total: 0,
      editAddressDialogVisibale: false,
      editAddressForm: {
        address1: [],
        address2: ''
      },
      editAddressFormRules: {
        address1: {
          required: true,
          message: '请选择省市区县',
          trigger: 'blur'
        },
        address2: {
          required: true,
          message: '请填写详细地址',
          trigger: 'blur'
        }
      },
      citydata,
      progressVisible: false,
      progressInfo: []
    }
  },
  computed: {},
  watch: {},
  created() {
    this.loadOrderList()
  },
  mounted() {},
  methods: {
    async loadOrderList() {
      const { data } = await this.$http.get('orders', {
        params: this.queryInfo
      })
      console.log(data)
      if (data.meta.status !== 200) {
        return this.$message.error('获取订单列表失败')
      }
      this.ordersList = data.data.goods
      this.total = data.data.total
    },
    handleSizeChange(newSize) {
      this.queryInfo.pagesize = newSize
      this.loadOrderList()
    },
    handleCurrentChange(newNum) {
      this.queryInfo.pagenum = newNum
      this.loadOrderList()
    },
    ShowEditAddress() {
      this.editAddressDialogVisibale = true
    },
    resetEditAddressForm() {
      this.$refs.editAddressFormRef.resetFields()
    },
    showProgress() {
      // const { data: res } = await this.$http.get('/kuaidi/1106975712662')
      // if (res.meta.status !== 200) {
      //   return this.$message.error('获取物流进度失败!')
      // }
      // this.progressInfo = res.data
      // this.progressVisible = true
    }
  }
}
</script>

<style scoped lang="less"></style>
